<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <title>我的</title>
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui2/aui.css" />
	<style>
	    html {
	        height: 100%;
	    }
	
	    body {
	        background-color: #DCDCDC;
	        height: 100%;
	    }
	
	    .avatar {
	        width: 80px;
	        height: 80px;
	        margin-left: 1em;
	        margin-top: 1em;
	        margin-right: 1em;
	    }
	
	    .itemheader {
	        width: 100%;
	        background: white;
	        margin-top: 0.2em;
	        margin-bottom: 0.6em;
	    }
	
	    .bottomitem {
	      margin-top: 30px;
	    }
	</style>
</head>

<body>
    <div class="aui-info itemheader">
        <div class="aui-info-item">
            <img  class="aui-img-round avatar" id="avatar" /><span class="aui-margin-l-5" id="nickname">我的昵称</span>
            </div>
        <div class="aui-info-item"></div>
    </div>

<ul class="aui-list aui-list-in">
      <li class="aui-list-item" tapmode onclick="openWin('user_detail_win')">
          <div class="aui-list-item-label-icon">
              <i class="aui-iconfont aui-icon-my"></i>
          </div>
          <div class="aui-list-item-inner">
              完善个人信息<i class="aui-iconfont aui-icon-right"></i>
          </div>
      </li>
      <li class="aui-list-item" tapmode onclick="openWin('class_win')">
          <div class="aui-list-item-label-icon">
              <i class="aui-iconfont aui-icon-cert"></i>
          </div>
          <div class="aui-list-item-inner">
              班级<i class="aui-iconfont aui-icon-right"></i>
          </div>
      </li>
      <li class="aui-list-item" tapmode onclick="openWin('my_message_win')">
          <div class="aui-list-item-label-icon">
              <i class="aui-iconfont aui-icon-cert"></i>
          </div>
          <div class="aui-list-item-inner">
              我的消息<i class="aui-iconfont aui-icon-right"></i>
          </div>
      </li>
      <li id="resource_li" class="aui-list-item" tapmode >
          <div class="aui-list-item-label-icon">
              <i class="aui-iconfont aui-icon-cart"></i>
          </div>
          <div class="aui-list-item-inner">
              <span id="resource"></span><i class="aui-iconfont aui-icon-right"></i>
          </div>
      </li>
      <li class="aui-list-item" tapmode onclick="openWin('my_collection_win')">
          <div class="aui-list-item-label-icon">
              <i class="aui-iconfont aui-icon-cart"></i>
          </div>
          <div class="aui-list-item-inner">
              我的收藏<i class="aui-iconfont aui-icon-right"></i>
          </div>
      </li>
      <li id="auth_teacher_li" class="aui-list-item" tapmode onclick="openWin('auth_teacher_win')">
          <div class="aui-list-item-label-icon">
              <i class="aui-iconfont aui-icon-mobile"></i>
          </div>
          <div class="aui-list-item-inner">
             教师认证<i class="aui-iconfont aui-icon-right"></i>
          </div>
      </li>
      <li class="aui-list-item" tapmode onclick="openWin('wallet_win')">
          <div class="aui-list-item-label-icon">
              <i class="aui-iconfont aui-icon-mobile"></i>
          </div>
          <div class="aui-list-item-inner">
              钱包<i class="aui-iconfont aui-icon-right"></i>
          </div>
      </li>
      <li class="aui-list-item" tapmode onclick="openWin('my_follow_win')">
          <div class="aui-list-item-label-icon">
              <i class="aui-iconfont aui-icon-star"></i>
          </div>
          <div class="aui-list-item-inner">
              我的关注<i class="aui-iconfont aui-icon-right"></i>
          </div>
      </li>
      <li class="aui-list-item" tapmode onclick="share();">
          <div class="aui-list-item-label-icon">
              <i class="aui-iconfont aui-icon-share"></i>
          </div>
          <div class="aui-list-item-inner">
              分享给好友<i class="aui-iconfont aui-icon-right"></i>
          </div>
      </li>

  </ul>
  <div class="bottomitem">
    <div class="aui-btn aui-btn-danger aui-btn-block aui-btn-sm" onclick="exit();">退出登录</div>
  </div>

</body>
<script data-main="../../script/main" src="../../script/require.js"></script>
<script type="text/javascript">
    var sharebox;
    apiready = function() {
    	require(["api","zepto","common","aui2/aui-sharebox"],function(){
			initResource();
			sharebox = new auiSharebox();    		
    	});
    }
    
    function openWin(window_name) {
		api.openWin({
            name : window_name,
            url : './'+window_name+'.html',
            bounces : false,
        });
	}
    
    function exit(){
        var ajpush = api.require('ajpush');
        ajpush.removeListener();
        ajpush.stopPush();
        var param = {id:-1};
        ajpush.clearNotification(param,function(ret) {
        });
    	$zb.prefs.removePrefs('token');
    	$zb.prefs.removePrefs('userInfo');
    	api.openWin({
            name : 'login',
            url : '../common/login.html',
            bounces : false,
            rect : {
                x : 0,
                y : 0,
                w : 'auto',
                h : 'auto'
            },
            slidBackEnabled:false,
            bgColor:'widget://image/login/bg.jpg'
        });
        api.closeFrameGroup({
            name: 'homepage'
        });
	}
	function initResource(){
		$zb.prefs.getPrefs('userInfo',function(result){
			if (result.value != "") {
				var userinfo = JSON.parse(result.value);
				$('#nickname').html(userinfo.nickname);
				if(userinfo.usertype == $zb.usertype.USERTYPE_STUDENT){
					$('#resource').text("已学课程");
					$('#resource_li').attr('onclick',"openWin('my_study_done_win')");
				}else if(userinfo.usertype == $zb.usertype.USERTYPE_TEACHER){
					$('#resource').text("我的资源");
					$('#resource_li').attr('onclick',"openWin('my_resource_win')");
					$('#auth_teacher_li').hide();
				}
				api.imageCache({
                    url: $zb.getRes_temp(userinfo.avatar),
                    encode: false
                }, function(ret, err) {
                    if (ret.status === true) {
	                    $('#avatar').attr('src',ret.url);
                    }
                });
			}
		})
	}
	function updateAvatar(){
		$zb.prefs.getPrefs('userInfo',function(result){
			if (result.value != "") {
				var userinfo = JSON.parse(result.value);
				$('#nickname').html(userinfo.nickname);
				api.imageCache({
                    url: $zb.getRes_temp(userinfo.avatar),
                    encode: false
                }, function(ret, err) {
                    if (ret.status === true) {
	                    $('#avatar').attr('src',ret.url);
                    }
                });
			}
		})
	}
	
	function share(){
	    var wx = api.require('wx');
        wx.isInstalled(function(ret, err) {
            if (ret.installed) {
                openSharebox();
            } else {
                api.toast({
	                msg:'当前设备未安装微信客户端'
                });
            }
        });
	}
	
    function openSharebox(){
        sharebox.init({
            frameBounces:false,//当前页面是否弹动，（主要针对安卓端）
            buttons:[{
                image:'../../image/share/wx.png',
                text:'微信',
                value:'wx'//可选
            },{
                image:'../../image/share/wx-circle.png',
                text:'朋友圈',
                value:'wx-circle'
            }],
            col:4,
            cancelTitle:'关闭'
        },function(ret){
            if(ret){
                var index = ret.buttonIndex;
                var type = index==1?"session":"timeline";
                shareWx(type);
            }
        })
    }
    
    function shareWx(type){
        var wx = api.require('wx');
        wx.shareImage({
            scene: type,
            contentUrl: 'widget://image/main/c1.jpg'
        }, function(ret, err) {
            if (ret.status) {
                api.toast({
	                msg:'分享成功'
                });
            } 
        });
    }
</script>
</html>
